
library(foreign)
library(ggplot2)
library(extrafont)
library(extrafont)
# font_import() # only do this one time - it takes a while

setwd("~/Replication")

#==========================================
# POLITY V
#==========================================

data <- read.csv("data/polityiv.csv")

data_sub <- data[data$country != "South Sudan",]


pdf("plots/polityv.pdf", width=6, height=4)
plot <- ggplot(data_sub,aes(x= reorder(country, polity2), 
                            polity2, fill=as.factor(reb_gov))) + geom_bar(stat ="identity") 
plot + labs(title = "", 
  x = "Country (green = rebel government)", 
  y = "Polity score", fill = NULL) + theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), 
  legend.position = "none") + 
  geom_vline(xintercept=26.5, linetype='dashed', col = 'black') +
  annotate("text", x = "Ethiopia", y = 7.5, label = "Below democracy", vjust = -0.5) +
  scale_fill_manual(values=c("#D3D3D3", "#2E8B57"))

dev.off()


#==========================================
# FREEDOM HOUSE
#==========================================

f_house <- read.csv("data/freedom_house.csv")

f_sub <- f_house[f_house$country != "South Sudan",]

pdf("plots/freedom_house.pdf", width=6, height=4)
f_plot <- ggplot(f_sub,aes(x= reorder(country, freedom_house_score), 
                         freedom_house_score, fill=as.factor(reb_gov))) + geom_bar(stat ="identity") 
f_plot + labs(title = "", 
  x = "Country (green = rebel government)", 
  y = "Freedom House score", fill = NULL) + theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), 
  legend.position = "none") +
  geom_vline(xintercept=18.5, linetype='dashed', col = 'black') +
  geom_vline(xintercept=39.5, linetype='dashed', col = 'black') +
  annotate("text", x = "Congo Kinshasa", y = 75, label = "Not free", vjust = -0.5) +
  annotate("text", x = "Niger", y = 75, label = "Partly free", vjust = -0.5) +
  scale_fill_manual(values=c("#D3D3D3", "#2E8B57"))
dev.off()
